package com.mediastory.spsserver.api.web;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.mediastory.spsserver.api.service.ApiSvc;

/**
 * @author Jaewon Choi
 */

@Controller
@RequestMapping(value={"/API/v1_0"})
public class Api_v1_0_Ctrl {
	
	private final Logger logger = Logger.getLogger(getClass());
	
	private final String apiVer = "1.0";
	
	@Autowired
	@Qualifier("ApiSvcImpl_v1_0")
	private ApiSvc apiSvc;

	/**
	 * 카테고리 목록을 json 형식으로 반환한다.
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/category/list", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getCategorys(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=false, value="datetime", defaultValue="")  String datetime) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();

		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("datetime", datetime);
			List<Object> categoryList = apiSvc.findbyListCategory(condition);
			resultMap.put("list", categoryList);
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "categoryList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("datetime", datetime);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			Calendar cal = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			resultMap.put("datetime", sdf.format(cal.getTime()));
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	
	/**
	 * 카테고리 목록을 json 형식으로 반환한다.
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/category", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getCategory(
			HttpServletRequest request
			, @RequestParam(required=true, value="categoryIdx") Integer categoryIdx
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=false, value="datetime", defaultValue="")  String datetime) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();

		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("datetime", datetime);
			condition.put("categoryIdx", categoryIdx);			
			List<Object> categoryList = apiSvc.findbyListCategory(condition);
			resultMap.put("list", categoryList);
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "categoryList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("datetime", datetime);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			Calendar cal = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			resultMap.put("datetime", sdf.format(cal.getTime()));
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 카테고리 내 콘텐츠 목록을 json 형식으로 반환한다.
	 * @PathVariable String categoryIdx 카테고리 idx
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/conts/{categoryIdx}", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getContents(
			HttpServletRequest request
			, @PathVariable Integer categoryIdx
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=false, value="datetime", defaultValue="")  String datetime) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("datetime", datetime);
			condition.put("categoryIdx", categoryIdx);
			//resultMap.put("list", apiSvc.findbyListInCont(condition));
			resultMap.put("list", apiSvc.findbyListInCont2(condition));
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "contList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("categoryIdx", categoryIdx);
			data.put("datetime", datetime);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			Calendar cal = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			resultMap.put("datetime", sdf.format(cal.getTime()));

			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");

		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 카테고리 내 콘텐츠 목록을 json 형식으로 반환한다.
	 * @PathVariable String categoryIdx 카테고리 idx
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/conts", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getContents(
			HttpServletRequest request
			, @RequestParam(required=true, value="lat") Float lat
			, @RequestParam(required=true, value="lng") Float lng
			, @RequestParam(required=true, value="listCount") Integer listCount			
			, @RequestParam(required=false, value="userIdx") Integer userIdx
			, @RequestParam(required=false, value="categoryIdx") Integer categoryIdx
			, @RequestParam(required=false, value="contIdx") Integer contIdx
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=false, value="datetime", defaultValue="")  String datetime) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
		
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("datetime", datetime);
			condition.put("lat", lat);
			condition.put("lng", lng);
			
			if(listCount == null || listCount<0 ) {
				listCount = 0;
			}
			condition.put("listCount", listCount);
			condition.put("listCountNext", listCount+20);	
			condition.put("userIdx", userIdx);
			condition.put("contIdx", contIdx);		
			
			resultMap.put("list", apiSvc.findbyListInCont2(condition));
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "contList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("datetime", datetime);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			Calendar cal = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			resultMap.put("datetime", sdf.format(cal.getTime()));

			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");

		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 카테고리 내 콘텐츠 목록을 json 형식으로 반환한다.
	 * @PathVariable String categoryIdx 카테고리 idx
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/cont", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getContent(
			HttpServletRequest request
			, @RequestParam(required=true, value="lat") Float lat
			, @RequestParam(required=true, value="lng") Float lng						
			, @RequestParam(required=false, value="userIdx") Integer userIdx
			, @RequestParam(required=true, value="contIdx") Integer contIdx
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=false, value="datetime", defaultValue="")  String datetime) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
		
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("datetime", datetime);
			condition.put("lat", lat);
			condition.put("lng", lng);			

			condition.put("userIdx", userIdx);
			condition.put("contIdx", contIdx);		
			
			resultMap.put("list", apiSvc.findbyListInCont2(condition));
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "contList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("datetime", datetime);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			Calendar cal = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			resultMap.put("datetime", sdf.format(cal.getTime()));

			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");

		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 카테고리 내 콘텐츠 목록을 json 형식으로 반환한다.
	 * @PathVariable String categoryIdx 카테고리 idx
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/contsMapview", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getContentsMapview(
			HttpServletRequest request
			, @RequestParam(required=true, value="lat") Float lat
			, @RequestParam(required=true, value="lng") Float lng
			, @RequestParam(required=true, value="listCount") Integer listCount
			, @RequestParam(required=true, value="lCount") Integer lCount	
			, @RequestParam(required=false, value="userIdx") Integer userIdx
			, @RequestParam(required=false, value="categoryIdx") Integer categoryIdx
			, @RequestParam(required=false, value="contIdx") Integer contIdx
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=false, value="datetime", defaultValue="")  String datetime) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
		
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("datetime", datetime);
			condition.put("lat", lat);
			condition.put("lng", lng);
			
			if(listCount == null || listCount<0 ) {
				listCount = 0;
			}
			condition.put("listCount", listCount);
			condition.put("listCountNext", listCount+lCount);	
			condition.put("userIdx", userIdx);
			condition.put("contIdx", contIdx);		
			
			resultMap.put("list", apiSvc.findbyListInCont2(condition));
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "contList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("datetime", datetime);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			Calendar cal = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			resultMap.put("datetime", sdf.format(cal.getTime()));

			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");

		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 로그를 남긴다. 
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @param String data json형식으로 된 로깅데이터
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value={"/contIn"}, method=RequestMethod.POST)
	public @ResponseBody Map<String, Object> contInsert(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=true, value="data")  String data
			, @RequestParam(required=false, value="contFile1")  MultipartFile contFile1
			, @RequestParam(required=false, value="contFile2")  MultipartFile contFile2
			, @RequestParam(required=false, value="contFile3")  MultipartFile contFile3) {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			String ip = request.getRemoteAddr();

			Map<String, Object> logInfo = new HashMap<String, Object>();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "contents");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);		
			
			/*
			System.out.println("data:" + data);
			System.out.println("contFiles:" + contFiles);						
			*/
			
			List<JSONObject> dataList =  (List<JSONObject>)new JSONParser().parse(data);
			Map<String, Object> contData = new HashMap<String, Object>();
			contData.put("dataList", dataList);
			//contData.put("contFiles", contFiles);
			contData.put("contFile1", contFile1);
			contData.put("contFile2", contFile2);
			contData.put("contFile3", contFile3);
			Integer result  = apiSvc.addContent(contData);
			
			//System.out.println("contIdx:" + result);
			
			resultMap.put("contIdx", result);
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 로그를 남긴다. 
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @param String data json형식으로 된 로깅데이터
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value={"/contUp"}, method=RequestMethod.POST)
	public @ResponseBody Map<String, Object> contUpdate(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=true, value="data")  String data
			, @RequestParam(required=false, value="contFile1")  MultipartFile contFile1
			, @RequestParam(required=false, value="contFile2")  MultipartFile contFile2
			, @RequestParam(required=false, value="contFile3")  MultipartFile contFile3) {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			String ip = request.getRemoteAddr();

			Map<String, Object> logInfo = new HashMap<String, Object>();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "contents");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			List<JSONObject> dataList =  (List<JSONObject>)new JSONParser().parse(data);
			Map<String, Object> contData = new HashMap<String, Object>();
			contData.put("dataList", dataList);
			
			apiSvc.updateContent(contData);			

			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 로그를 남긴다. 
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @param String data json형식으로 된 로깅데이터
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value={"/commentIn"}, method=RequestMethod.POST)
	public @ResponseBody Map<String, Object> commentInsert(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=true, value="data")  String data) {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			String ip = request.getRemoteAddr();

			Map<String, Object> logInfo = new HashMap<String, Object>();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "contents");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);			

			List<JSONObject> dataList =  (List<JSONObject>)new JSONParser().parse(data);
			Map<String, Object> contData = new HashMap<String, Object>();
			contData.put("dataList", dataList);
			Integer result  = apiSvc.addComment(contData);
			
			resultMap.put("contIdx", result);
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 로그를 남긴다. 
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @param String data json형식으로 된 로깅데이터
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value={"/commentUp"}, method=RequestMethod.POST)
	public @ResponseBody Map<String, Object> commentUpdate(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=true, value="data")  String data) {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			String ip = request.getRemoteAddr();

			Map<String, Object> logInfo = new HashMap<String, Object>();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "contents");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			List<JSONObject> dataList =  (List<JSONObject>)new JSONParser().parse(data);
			Map<String, Object> contData = new HashMap<String, Object>();
			contData.put("dataList", dataList);
			
			apiSvc.updateComment(contData);			

			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 카테고리 내 콘텐츠 목록을 json 형식으로 반환한다.
	 * @PathVariable String categoryIdx 카테고리 idx
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/comments", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getComments(
			HttpServletRequest request	
			, @RequestParam(required=false, value="userIdx") Integer userIdx
			, @RequestParam(required=false, value="contIdx") Integer contIdx
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=false, value="datetime", defaultValue="")  String datetime) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
		
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("datetime", datetime);
			condition.put("userIdx", userIdx);
			condition.put("contIdx", contIdx);		
			
			resultMap.put("list", apiSvc.findbyListInComment(condition));
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "commentList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("datetime", datetime);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			Calendar cal = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			resultMap.put("datetime", sdf.format(cal.getTime()));

			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");

		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	
	/**
	 * 메인페이지의 콘텐츠 목록을 json 형식으로 반환한다.
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/main/conts", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getMainCont(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=false, value="datetime", defaultValue="")  String datetime) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("datetime", datetime);
			resultMap.put("list", apiSvc.findbyListMainCont(condition));
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "mainContList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("datetime", datetime);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
			Calendar cal = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			resultMap.put("datetime", sdf.format(cal.getTime()));

		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 공지사항/FAQ의 신규/변경 항목이 있는지 json 형식으로 반환한다.
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @param String datetime 검색시각
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/notice/isNew", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getNoticeIsNew(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=false, value="datetime", defaultValue="")  String datetime) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("datetime", datetime);
			resultMap.put("isNew", apiSvc.findbyNoticeIsNew(condition));
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "noticeIsNew");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("datetime", datetime);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			Calendar cal = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			resultMap.put("datetime", sdf.format(cal.getTime()));
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 긴급공지를 json 형식으로 반환한다.
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/notice/main", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getNoticeMain(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("main", true);
			Object notice = apiSvc.findbyNotice(condition);
			resultMap.put("notice", notice);
			
			if(notice != null){
				resultMap.put("isEmpty", "N");
			}else{
				resultMap.put("isEmpty", "Y");
			}
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "noticeMain");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			apiSvc.addLogInfo(logInfo);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 긴급공지를 json 형식으로 반환한다.
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/notice", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getNoticeList(
			HttpServletRequest request
			, @RequestParam(required=true, value="categoryIdx")  String categoryIdx
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("main", true);
			condition.put("categoryIdx", categoryIdx);
			//Object notice = apiSvc.findbyNoticeList(condition);
			resultMap.put("list", apiSvc.findbyNoticeList(condition));
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "noticeMain");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			apiSvc.addLogInfo(logInfo);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 긴급공지를 json 형식으로 반환한다.
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/urgencyNotice", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getUrgencyNoticeList(
			HttpServletRequest request
			, @RequestParam(required=true, value="categoryIdx")  String categoryIdx
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("main", true);
			condition.put("categoryIdx", categoryIdx);
			//resultMap.put("list", apiSvc.findbyUrgencyNotice(condition));
			Object urgencyNotice = apiSvc.findbyUrgencyNotice(condition);
			resultMap.put("urgencyNotice", urgencyNotice);
			
			if(urgencyNotice != null){
				resultMap.put("isEmpty", "N");
			}else{
				resultMap.put("isEmpty", "Y");
			}
			
			
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "noticeMain");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			apiSvc.addLogInfo(logInfo);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	
	/**
	 * 소개/제휴문의 데이터를 json 형식으로 반환한다.
	 * 	@PathVariable String gubun 구분값(소개:info, 제휴문의:partner)
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/info/{gubun}", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getInfo(
			HttpServletRequest request
			, @PathVariable String gubun
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("gubun", gubun);
			resultMap.put("info", apiSvc.findbyInfo(condition));
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "info_"+gubun);
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("gubun", gubun);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 마켓별 버전 데이터를 json 형식으로 반환한다.
	 * 	@PathVariable String market 마켓 
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/version", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getVersion(
			HttpServletRequest request
			, @RequestParam(required=true, value="categoryIdx")  String categoryIdx
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();

		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("categoryIdx", categoryIdx);
			condition.put("storeType", storeType);
			resultMap.put("version", apiSvc.findbyVerMngr2(condition));
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "version");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 광고 카테고리 내 광고 목록을 json 형식으로 반환한다.
	 * @PathVariable String categoryIdx 카테고리 idx
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/ad/{adCategoryIdx}", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getAds(
			HttpServletRequest request
			, @PathVariable Integer adCategoryIdx
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer) {
		Map<String, Object> resultMap = new HashMap<String, Object>();

		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("adCategoryIdx", adCategoryIdx);
			resultMap.put("list", apiSvc.findbyListAdvertising(condition));
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "adList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("adCategoryIdx", adCategoryIdx);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 광고 카테고리 내 광고 목록을 json 형식으로 반환한다.
	 * @PathVariable String categoryIdx 카테고리 idx
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/adList", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getAdsList(
			HttpServletRequest request
			, @RequestParam(required=true, value="categoryIdx")  String categoryIdx
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer) {
		Map<String, Object> resultMap = new HashMap<String, Object>();

		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("categoryIdx", categoryIdx);
			resultMap.put("list", apiSvc.findbyListAdvertising(condition));
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "adList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 광고 카테고리 내 광고 목록을 json 형식으로 반환한다.
	 * @PathVariable String categoryIdx 카테고리 idx
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/issueList", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getIssueList(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer) {
		Map<String, Object> resultMap = new HashMap<String, Object>();

		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			resultMap.put("list", apiSvc.findbyListAdvertising(condition));
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "adList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 카테고리 목록을 json 형식으로 반환한다.
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/android/payContList", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getPayContAndroid(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=false, value="datetime", defaultValue="")  String datetime) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();

		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("datetime", datetime);
			List<Object> categoryList = apiSvc.findbyListPayContAndroid(condition);
			resultMap.put("list", categoryList);
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "categoryList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("datetime", datetime);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			Calendar cal = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			resultMap.put("datetime", sdf.format(cal.getTime()));
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 카테고리 목록을 json 형식으로 반환한다.
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/ios/payContList", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getPayContIos(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=false, value="datetime", defaultValue="")  String datetime) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();

		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("datetime", datetime);
			List<Object> categoryList = apiSvc.findbyListPayContIos(condition);
			resultMap.put("list", categoryList);
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "categoryList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("datetime", datetime);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			Calendar cal = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			resultMap.put("datetime", sdf.format(cal.getTime()));
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 카테고리 목록을 json 형식으로 반환한다.
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/guide", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getGuide(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=false, value="datetime", defaultValue="")  String datetime) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();

		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("datetime", datetime);
			List<Object> categoryList = apiSvc.findbyListGuide(condition);
			resultMap.put("list", categoryList);
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "categoryList");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("datetime", datetime);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			Calendar cal = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			resultMap.put("datetime", sdf.format(cal.getTime()));
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * GCM을 위한 기기 데이터를 등록/해제한다.
	 * @PathVariable String type 등록(on)/해제(off)
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/gcm/{type}", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> setGcmData(
			HttpServletRequest request
			, @PathVariable String type
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=true, value="key")  String key) {
		Map<String, Object> resultMap = new HashMap<String, Object>();

		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id", deviceId);
			condition.put("key", key);
			if(type.equals("on") && key != null && ! key.equals("")){
				apiSvc.addGcmDevice(condition);
			}else if(type.equals("off")){
				apiSvc.removeGcmDevice(condition);
			}else{
				throw new Exception("[ERROR] error ");
			}
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "gcm_"+type);
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("key", key);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * GCM을 위한 기기 데이터를 등록/해제한다.
	 * @PathVariable String type 등록(on)/해제(off)
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/apns/{type}", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> setApnsData(
			HttpServletRequest request
			, @PathVariable String type
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=true, value="device_token")  String deviceToken
			, @RequestParam(required=true, value="gubun")  String gubun) {
		Map<String, Object> resultMap = new HashMap<String, Object>();

		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("deviceToken", deviceToken);
			condition.put("gubun", gubun);
			if(type.equals("on") && deviceToken != null && ! deviceToken.equals("")){
				apiSvc.addApnsDevice(condition);
			}else if(type.equals("off")){
				apiSvc.removeApnsDevice(condition);
			}else{
				throw new Exception("[ERROR] error ");
			}
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "apns_"+type);
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("deviceToken", deviceToken);
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 로그를 남긴다. 
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @param String data json형식으로 된 로깅데이터
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value={"/logUpload2"}, method=RequestMethod.POST)
	public @ResponseBody Map<String, Object> logUpload(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=true, value="data")  String data) {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			String ip = request.getRemoteAddr();

			Map<String, Object> logInfo = new HashMap<String, Object>();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "logging");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			logInfo.put("data", data.toString());
			String osGubun = "";
			
			if(storeType.equals("APPLE")) {
				osGubun = "iOS";
			} else if (storeType.equals("GOOGLE") || storeType.equals("OLLEH") || storeType.equals("NAVER") || storeType.equals("TSTORE") || storeType.equals("SAMSUNG") || storeType.equals("OZSTORE")) {
				osGubun = "Android";
			} else {
				osGubun = "etc";
			}
			
			logInfo.put("osGubun", osGubun);
			
			List<JSONObject> dataList =  (List<JSONObject>)new JSONParser().parse(data);
			Map<String, Object> logData = new HashMap<String, Object>();
			logData.put("logInfo", logInfo);
			logData.put("dataList", dataList);
			
			int result  = apiSvc.addLogging(logData);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 로그를 남긴다. 
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @param String data json형식으로 된 로깅데이터
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value={"/logUpload"}, method=RequestMethod.POST, headers={"Content-Encoding=gzip"})
	public @ResponseBody Map<String, Object> logUpload(HttpServletRequest request) {
		

		Map<String, Object> resultMap = new HashMap<String, Object>();
	
		InputStream is = null;
		GZIPInputStream gzipInputStream = null;
		ByteArrayOutputStream baos = null;
		try {
			is = request.getInputStream();
			gzipInputStream = new GZIPInputStream(is);
			
			baos = new ByteArrayOutputStream();
		    for (int value = 0; value != -1;) {
		        value = gzipInputStream.read();
		        if (value != -1) {
		            baos.write(value);
		        }
		    }
		    gzipInputStream.close();
		    baos.close();
		    String gzipData = new String(baos.toByteArray(), "UTF-8");
		    JSONObject dataObj =  (JSONObject)new JSONParser().parse(gzipData);

		    String ip = request.getRemoteAddr();
		    String deviceId = (String)dataObj.get("device_id");
		    String model = (String)dataObj.get("model");
		    String osVer = (String)dataObj.get("os_ver");
		    String lcdSize = (String)dataObj.get("lcd_size");
		    String storeType = (String)dataObj.get("store_type");
		    String appId = (String)dataObj.get("app_id");
		    String appVer = (String)dataObj.get("app_ver");
		    String deviceTime = (String)dataObj.get("device_time");
		    List<JSONObject> dataList =  (List<JSONObject>)dataObj.get("data");
		    String data = dataList.toString();
		    String osGubun = "";

			Map<String, Object> logInfo = new HashMap<String, Object>();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "logging");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			logInfo.put("deviceTime", deviceTime);
			logInfo.put("data", data.toString());
			
			if(storeType.equals("APPLE")) {
				osGubun = "iOS";
			} else if (storeType.equals("GOOGLE") || storeType.equals("OLLEH") || storeType.equals("NAVER") || storeType.equals("TSTORE") || storeType.equals("SAMSUNG") || storeType.equals("OZSTORE")) {
				osGubun = "Android";
			} else {
				osGubun = "etc";
			}
			
			logInfo.put("osGubun", osGubun);
			
			Map<String, Object> logData = new HashMap<String, Object>();
			logData.put("logInfo", logInfo);
			logData.put("dataList", dataList);

			int result  = apiSvc.addLogging(logData);

			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}
		return resultMap;

	}

	
	/**
	 * 로그를 남긴다. 
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @param String data json형식으로 된 로깅데이터
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value={"/logUpload3"}, method=RequestMethod.POST)
	public @ResponseBody Map<String, Object> logUpload3(HttpServletRequest request) {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		try {
		    String gzipData = ServletRequestUtils.getRequiredStringParameter(request, "gzipData");
		    JSONObject dataObj =  (JSONObject)new JSONParser().parse(gzipData);
		    
		    String ip = request.getRemoteAddr();
		    String deviceId = (String)dataObj.get("device_id");
		    String model = (String)dataObj.get("model");
		    String osVer = (String)dataObj.get("os_ver");
		    String lcdSize = (String)dataObj.get("lcd_size");
		    String storeType = (String)dataObj.get("store_type");
		    String appId = (String)dataObj.get("app_id");
		    String appVer = (String)dataObj.get("app_ver");
		    String deviceTime = (String)dataObj.get("device_time");
		    List<JSONObject> dataList =  (List<JSONObject>)dataObj.get("data");
		    String data = dataList.toString();
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "logging");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			logInfo.put("deviceTime", deviceTime);
			logInfo.put("data", data.toString());

			Map<String, Object> logData = new HashMap<String, Object>();
			logData.put("logInfo", logInfo);
			logData.put("dataList", dataList);
			
			int result  = apiSvc.addLogging(logData);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * 로그를 남긴다. 
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @param String data json형식으로 된 로깅데이터
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value={"/purchaseUpload"}, method=RequestMethod.POST)
	public @ResponseBody Map<String, Object> purchaseUpload(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=true, value="os_gubun")  String osGubun
			, @RequestParam(required=true, value="data")  String data) {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			String ip = request.getRemoteAddr();

			Map<String, Object> logInfo = new HashMap<String, Object>();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "logging");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			logInfo.put("data", data.toString());
			
			List<JSONObject> dataList =  (List<JSONObject>)new JSONParser().parse(data);
			Map<String, Object> logData = new HashMap<String, Object>();
			logData.put("logInfo", logInfo);
			logData.put("dataList", dataList);
			logData.put("osGubun", osGubun);
			
			logInfo.put("osGubun", osGubun);
			
			int result  = apiSvc.addPurchaseData(logData);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
		

	/**
	 * 로그를 남긴다. 
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @param String data json형식으로 된 로깅데이터
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value={"/purchaseUploadGzip"}, method=RequestMethod.POST, headers={"Content-Encoding=gzip"})
	public @ResponseBody Map<String, Object> purchaseUploadGzip(HttpServletRequest request) {
		

		Map<String, Object> resultMap = new HashMap<String, Object>();
	
		InputStream is = null;
		GZIPInputStream gzipInputStream = null;
		ByteArrayOutputStream baos = null;
		try {
			is = request.getInputStream();
			gzipInputStream = new GZIPInputStream(is);
			
			baos = new ByteArrayOutputStream();
		    for (int value = 0; value != -1;) {
		        value = gzipInputStream.read();
		        if (value != -1) {
		            baos.write(value);
		        }
		    }
		    gzipInputStream.close();
		    baos.close();
		    String gzipData = new String(baos.toByteArray(), "UTF-8");
		    JSONObject dataObj =  (JSONObject)new JSONParser().parse(gzipData);

		    String ip = request.getRemoteAddr();
		    String deviceId = (String)dataObj.get("device_id");
		    String model = (String)dataObj.get("model");
		    String osVer = (String)dataObj.get("os_ver");
		    String lcdSize = (String)dataObj.get("lcd_size");
		    String storeType = (String)dataObj.get("store_type");
		    String appId = (String)dataObj.get("app_id");
		    String appVer = (String)dataObj.get("app_ver");
		    String deviceTime = (String)dataObj.get("device_time");
		    String osGubun = (String)dataObj.get("os_gubun");
		    List<JSONObject> dataList =  (List<JSONObject>)dataObj.get("data");
		    String data = dataList.toString();

			Map<String, Object> logInfo = new HashMap<String, Object>();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "logging");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			logInfo.put("deviceTime", deviceTime);
			logInfo.put("data", data.toString());

			Map<String, Object> logData = new HashMap<String, Object>();
			logData.put("logInfo", logInfo);
			logData.put("dataList", dataList);
			logData.put("osGubun", osGubun);
			
			int result  = apiSvc.addPurchaseData(logData);

			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;

	}
	

	/**
	 * 로그를 남긴다. 
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @param String data json형식으로 된 로깅데이터
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value={"/testUpload"}, method=RequestMethod.POST)
	public @ResponseBody Map<String, Object> testUpload(
			HttpServletRequest request
			, @RequestParam(required=true, value="device_id")  String deviceId
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer
			, @RequestParam(required=true, value="os_gubun")  String osGubun
			, @RequestParam(required=true, value="data")  String data) {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			String ip = request.getRemoteAddr();

			Map<String, Object> logInfo = new HashMap<String, Object>();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "logging");
			logInfo.put("deviceId", deviceId);
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			logInfo.put("data", data.toString());
			
			List<JSONObject> dataList =  (List<JSONObject>)new JSONParser().parse(data);
			Map<String, Object> logData = new HashMap<String, Object>();
			logData.put("logInfo", logInfo);
			logData.put("dataList", dataList);
			logData.put("osGubun", osGubun);
			
			int result  = apiSvc.addPurchaseData(logData);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
	/**
	 * app id를 json 형식으로 반환한다.
	 * @PathVariable String categoryIdx 카테고리 idx
	 * @param String device_id 단말ID
	 * @param String model 단말 모델명
	 * @param String os_ver 단말 OS버전
	 * @param String lcd_size 단말 LCD 크기
	 * @param String store_type 앱스토어 구분
	 * @param String app_id 컨테이너 앱 아이디
	 * @param String app_ver 컨테이너 앱 버전
	 * @return Map<String, Object> json 형식으로 반환
	 * */
	@RequestMapping(value="/appUniqueNo", headers="Accept=application/json")
	public @ResponseBody Map<String, Object> getAppSeqId(
			HttpServletRequest request
			, @RequestParam(required=true, value="model")  String model
			, @RequestParam(required=true, value="os_ver")  String osVer
			, @RequestParam(required=true, value="lcd_size")  String lcdSize
			, @RequestParam(required=true, value="store_type")  String storeType
			, @RequestParam(required=true, value="app_id")  String appId
			, @RequestParam(required=true, value="app_ver")  String appVer) {
		Map<String, Object> resultMap = new HashMap<String, Object>();

		try {
			Map<String, Object> condition = new HashMap<String, Object>();

			resultMap.put("appUniqueNo", apiSvc.findbyAppSeqId());
			
			Map<String, Object> logInfo = new HashMap<String, Object>();
			String ip = request.getRemoteAddr();
			logInfo.put("ip", ip);
			logInfo.put("apiVer", apiVer);
			logInfo.put("cmd", "appSeqId");
			logInfo.put("version", "1.0");
			logInfo.put("deviceId", "");
			logInfo.put("model", model);
			logInfo.put("osVer", osVer);
			logInfo.put("lcdSize", lcdSize);
			logInfo.put("storeType", storeType);
			logInfo.put("appId", appId);
			logInfo.put("appVer", appVer);
			Map<String, Object> data = new HashMap<String, Object>();
			
			logInfo.put("data", data.toString());
			apiSvc.addLogInfo(logInfo);
			
			resultMap.put("returnCode", "000");
			resultMap.put("returnMessage", "Success");
		} catch (Exception e) {
			// TODO: handle exception
			//e.printStackTrace();
			logger.error("[ERROR]", e);
			resultMap = new HashMap<String, Object>();
			resultMap.put("returnCode", "001");
			resultMap.put("returnMessage", "[ERROR]communication error.");
		}

		return resultMap;
	}
	
}